package conson.tech.manage.message;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @ClassName Swagger2
 * @Description
 * @Author HXL
 * @Date 2019-10-08
 * @Version 1.0
 */
@ComponentScan("conson.tech.manage.message.controller")
@Configuration
//@EnableWebMvc
@EnableSwagger2
public class Swagger2 {

    @Value("${swagger.enable}")
    private boolean enableSwagger;
    @Bean
    public Docket createRestApi(){
        //ParameterBuilder tokenPar = new ParameterBuilder();
        //List<Parameter> pars = new ArrayList<>();
        //tokenPar.name("uid").description("用户ID").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
        //pars.add(tokenPar.build());


        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).
                enable(enableSwagger)
                .select()
                //.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .apis(RequestHandlerSelectors.basePackage("conson.tech.manage.message.controller"))
                .paths(PathSelectors.any())
                //.build().globalOperationParameters(pars).apiInfo(apiInfo());
                .build();
    }
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder().title("便捷青岛API")
                .version("1.0.0").description("便捷青岛").build();
    }
}
